import collections
import os, sys
import time
import re

def m(a):
  with open(a, encoding='utf8', mode='r') as f:
    s=f.read()
  s3=['A1','A2','A3','A4','A5','B1','B2','B3','B4','B5','C1','C2','C3','C4','C5']
  s2 = re.findall(r'function ([^t][0-9])\(\)', s)
  s5 = re.findall(r'function (t[0-9])\(\)', s)

  s2=s2[:15]
  s6_trans= dict(zip(s2,s3))
  print("转换时间间隔，例如\nt1(\" . . \"):2 , t2(\" . \"):1 , t3(\" . . . . \"):4 , t4(\" \"): 0")
  s12=""
  for i in range(len(s5)):
    s14=int(input("%s : " %s5[i]))
    s6_trans[s5[i]]= " %s " %' '.join(s14*['.'])
    if s14==0:
      s12=s5[i]
    if s14==1:
      s13=s5[i]
  if s12!="":
    s15=input("建议把两个连续的%s项替换为%s，要这样做吗？([y]/n)" %(s12, s13))
    if s15=="" or s15=="y" or s15=="Y":
      s=s.replace("%s();%s();" %(s12,s12), "%s();" %(s13))
  print(s6_trans) 

  s8=re.compile(r'([a-zA-Z][0-9])\(\);')
  s9=s8.findall(s)
  print(s9)
  s10=[s6_trans[i] for i in s9]
  s11= ''.join(s10).replace('  ', ' ')
  print(s11)
  rate= int(60000/int(input("Gap :(int) ")))
  with open("%s.txt" %os.path.basename(a)[:-3], mode='w', encoding='utf8') as f:
    f.write('<DontCopyThisLine> %s 0 16 Unknown Unknown\n%s' %(rate, s11))


if __name__ == "__main__":
  if len(sys.argv[1:]) ==0:
    print("")
    sys.exit()
  for i in sys.argv[1:]:
    i= i.strip('\'\"\\').rstrip('/')
    if i[-3:]==".js":
      try:
        m(i)
      except Exception as e:
        print(e)
        input()
